// 笔试强训day28:体操队形

#include <iostream>
#include <vector>
using namespace std;

int ans = 0, n = 0;

void dfs(vector<int>& a, vector<bool>& isPlaced, int pos)
{
    if(pos == n + 1)
    {
        ans++;
        return;
    }
    for(int i = 1; i <= n; i++)
    {
        if(isPlaced[i] == true)
            continue;
        if(isPlaced[a[i]] == true)
            return;
        
        isPlaced[i] = true;
        dfs(a, isPlaced, pos + 1);
        isPlaced[i] = false;
    }
}

int main() {
    cin >> n;
    vector<int> a(n + 1);
    vector<bool> isPlaced(n + 1, false);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    dfs(a, isPlaced, 1);
    cout << ans << endl;

    return 0;
}